home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / gen / SLList.hP < prev    next >
Text File  |  1992-09-25  |  3KB  |  138 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // WARNING: This file is obsolete.  Use ../SLList.h, if you can.
  3. /* 
  4. Copyright (C) 1988 Free Software Foundation
  5.     written by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20.  
  21. #ifndef _<T>SLList_h
  22. #ifdef __GNUG__
  23. #pragma interface
  24. #endif
  25. #define _<T>SLList_h 1
  26.  
  27. #include <Pix.h>
  28. #include "<T>.defs.h"
  29.  
  30. #ifndef _<T>SLListNode_h
  31. #define _<T>SLListNode_h 1
  32.  
  33. struct <T>SLListNode
  34. {
  35.   <T>SLListNode*         tl;
  36.   <T>                    hd;
  37.                          <T>SLListNode() { }
  38.                          <T>SLListNode(const <T&> h, <T>SLListNode* t = 0);
  39.                          ~<T>SLListNode() { }
  40. };
  41.  
  42.  
  43. inline <T>SLListNode::<T>SLListNode(const <T&> h, <T>SLListNode* t)
  44. :hd(h), tl(t) {}
  45.  
  46. typedef <T>SLListNode* <T>SLListNodePtr;
  47.  
  48. #endif
  49.  
  50.  
  51. class <T>SLList
  52. {
  53. protected:
  54.   <T>SLListNode*        last;
  55.  
  56. public:
  57.                         <T>SLList();
  58.                         <T>SLList(const <T>SLList& a);
  59.                         ~<T>SLList();
  60.  
  61.   <T>SLList&            operator = (const <T>SLList& a);
  62.  
  63.   int                   empty();
  64.   int                   length();
  65.  
  66.   void                  clear();
  67.  
  68.   Pix                   prepend(<T&> item);
  69.   Pix                   append(<T&> item);
  70.  
  71.   void                  join(<T>SLList&);
  72.  
  73.   Pix                   prepend(<T>SLListNode*);
  74.   Pix                   append(<T>SLListNode*);
  75.  
  76.   <T>&                  operator () (Pix p);
  77.   Pix                   first();
  78.   void                  next(Pix& p);
  79.   int                   owns(Pix p);
  80.   Pix                   ins_after(Pix p, <T&> item);
  81.   void                  del_after(Pix p);
  82.  
  83.   <T>&                  front();
  84.   <T>&                  rear();
  85.   <T>                   remove_front();
  86.   int                   remove_front(<T>& x);
  87.   void                  del_front();
  88.  
  89.   void                  error(const char* msg);
  90.   int                   OK();
  91. };
  92.  
  93. inline <T>SLList::~<T>SLList()
  94. {
  95.   clear();
  96. }
  97.  
  98. inline <T>SLList::<T>SLList()
  99. {
  100.   last = 0;
  101. }
  102.  
  103. inline int <T>SLList::empty()
  104. {
  105.   return last == 0;
  106. }
  107.  
  108.  
  109. inline Pix <T>SLList::first()
  110. {
  111.   return (last == 0)? 0 : Pix(last->tl);
  112. }
  113.  
  114. inline void <T>SLList::next(Pix& p)
  115. {
  116.   p = (p == 0 || p == last)? 0 : Pix(((<T>SLListNode*)(p))->tl);
  117. }
  118.  
  119. inline <T>& <T>SLList::operator () (Pix p)
  120. {
  121.   if (p == 0) error("null Pix");
  122.   return ((<T>SLListNode*)(p))->hd;
  123. }
  124.  
  125. inline <T>& <T>SLList::front()
  126. {
  127.   if (last == 0) error("front: empty list");
  128.   return last->tl->hd;
  129. }
  130.  
  131. inline <T>& <T>SLList::rear()
  132. {
  133.   if (last == 0) error("rear: empty list");
  134.   return last->hd;
  135. }
  136.  
  137. #endif
  138.